<template>
  <div>
    <div class="left">
      <p>
        <el-button type="primary"  @click="$router.push('/user')">个人中心</el-button>
      </p>
      <p>
        <el-button @click="$router.push('/collection')">我的收藏</el-button>
      </p>
    </div>

    <div class="main">
      <p>USER/CENTER</p>
      <p>个人中心</p>
      <el-form :model="info" label-width="80px">
        <el-form-item label="账号">
          <el-input v-model="info.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="info.password"></el-input>
        </el-form-item>
        <el-form-item label="姓名">
          <el-input v-model="info.name"></el-input>
        </el-form-item>
        <el-form-item label="年龄">
          <el-input v-model="info.age"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-input v-model="info.gender"></el-input>
        </el-form-item>
        <el-form-item label="手机">
          <el-input v-model="info.phone"></el-input>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="info.email"></el-input>
        </el-form-item>
        <el-form-item label="照片" >
          <img :src="info.photo" alt="" style="width:150px;height:150px">
        </el-form-item>
      </el-form>
      <span slot="footer" >
        <el-button type="primary" @click="update">更新信息</el-button>
      </span>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      info: {},
      nowImg: "",
    };
  },
  methods: {
    async update() {
      let { data: res } = await this.$axios.post("/user/update",this.info);
      if (res.code != 200) return this.$message.error(res.message);
      this.$message.success(res.code);
    },
    async getUpdate() {
      this.info.photo = this.nowImg;
      let { data: res } = await this.$axios.get("/user/getlist" );
      this.info = res.data.list[0];
    },
  },
  created(){
    this.getUpdate()
  }
};
</script>

<style lang="scss" scoped>
.left {
  position: absolute;
  left: 300px;
  top: 200px;
}
.main {
  width: 40%;
  margin: 0 auto;
  p {
    font-size: 20px;
    font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
    text-align: center;
  }
  span {
    width: 100px;
    margin: 10px auto;
    text-align: center;
    display: flex;
    justify-content: center;
  }
  img{
    border-radius: 10px;
  }
}

</style>